﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace MyOCR
{
    /// <summary>
    /// 
    /// </summary>
    public class SetUpSave : INotifyPropertyChanged
    {
        #region baidu
        private string baidu_App_Id;

        public string BaiDu_App_Id
        {
            get { return baidu_App_Id; }
            set {
                baidu_App_Id = value; 
                NotifyPropertyChanged(nameof(BaiDu_App_Id));
            }
        }

        private string baidu_Api_Key;

        public string BaiDu_Api_Key
        {
            get { return baidu_Api_Key; }
            set {
                baidu_Api_Key = value;
                NotifyPropertyChanged(nameof(BaiDu_Api_Key));
            }
        }

        private string baidu_Secret_Key;

        public string BaiDu_Secret_Key
        {
            get { return baidu_Secret_Key; }
            set {
                baidu_Secret_Key = value;
                NotifyPropertyChanged(nameof(baidu_Secret_Key));
            }
        }
        #endregion

        #region SouGou
        private string sougou_Pid;

        public string SouGou_Pid
        {
            get { return sougou_Pid; }
            set {
                sougou_Pid = value;
                NotifyPropertyChanged(nameof(SouGou_Pid));
            }
        }
        private string sougou_Key;

        public string SouGou_Key
        {
            get { return sougou_Key; }
            set {
                sougou_Key = value;
                NotifyPropertyChanged(nameof(SouGou_Key));
            }
        }

        #endregion

        #region TengXun
        private string tengxun_App_Id;

        public string TengXun_App_Id
        {
            get { return tengxun_App_Id; }
            set {
                tengxun_App_Id = value;
                NotifyPropertyChanged(nameof(TengXun_App_Id));
            }
        }

        private string tengxun_Secret_Id;

        public string TengXun_Secret_Id
        {
            get { return tengxun_Secret_Id; }
            set {
                tengxun_Secret_Id = value;
                NotifyPropertyChanged(nameof(TengXun_Secret_Id));
            }
        }

        private string tengxun_Secret_Key;

        public string TengXun_Secret_Key
        {
            get { return tengxun_Secret_Key; }
            set {
                tengxun_Secret_Key = value;
                NotifyPropertyChanged(nameof(TengXun_Secret_Key));
            }
        }

        #endregion

        #region YouDao
        private string youdao_App_Key;

        public string YouDao_App_Key
        {
            get { return youdao_App_Key; }
            set {
                youdao_App_Key = value;
                NotifyPropertyChanged(nameof(YouDao_App_Key));
            }
        }
        private string youdao_App_Secret;

        public string YouDao_App_Secret
        {
            get { return youdao_App_Secret; }
            set {
                youdao_App_Secret = value;
                NotifyPropertyChanged(nameof(YouDao_App_Secret));
            }
        }

        #endregion

        #region 翻译与识别接口
        //识别
        private string recognition;

        public string _Recongnition
        {
            get { return recognition; }
            set {
                recognition = value;
                NotifyPropertyChanged(nameof(_Recongnition));
            }
        }

        //翻译
        private string translate;

        public string _Translate
        {
            get { return translate; }
            set {
                translate = value;
                NotifyPropertyChanged(nameof(_Translate));
            }
        }
        #endregion

        #region 自启与自动翻译
        private bool autoTranslation;

        public bool _AutoTranslation
        {
            get { return autoTranslation; }
            set
            {
                autoTranslation = value;
                NotifyPropertyChanged(nameof(_AutoTranslation));
            }
        }

        private bool selfStart;

        public bool _SelfStart
        {
            get { return selfStart; }
            set
            {
                selfStart = value;
                NotifyPropertyChanged(nameof(_SelfStart));
            }
        }
        #endregion

        private string language;

        public string _Language {
            get { return language; }
            set
            {
                language = value;
                NotifyPropertyChanged(nameof(_Language));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public void Save()
        {
            var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SetUpSave.xml");

            using (var stream = File.Open(filepath, FileMode.Create))
            {
                var serializer = new XmlSerializer(typeof(SetUpSave));
                serializer.Serialize(stream, this);
            }
        }

        public static SetUpSave Create()
        {
            var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SetUpSave.xml");

            if (File.Exists(filepath))
            {
                using (var stream = File.OpenRead(filepath))
                {
                    var serializer = new XmlSerializer(typeof(SetUpSave));
                    return serializer.Deserialize(stream) as SetUpSave;
                }
            }
            else
            {
                return new SetUpSave();
            }
        }
    }
}
